<script lang="ts" setup>
import { getCurrentInstance, reactive, ref } from 'vue'
import { onPageScroll, onReady } from '@dcloudio/uni-app'
import { tnNavPage } from '@tuniao/tnui-vue3-uniapp/utils'
import type { NavbarRectInfo } from '@tuniao/tnui-vue3-uniapp/components/navbar'
import PageContainer from '@/components/page-container/index.vue'
import useZPaging from '@/uni_modules/z-paging/components/z-paging/js/hooks/useZPaging.js'
import { useScrollTransparentNavbar } from '@/hooks'
import system from '@/api/system.js'
import { FILE_URL } from '@/api/config.js'

const paging = ref(null)
useZPaging(paging)
// 导航栏的高度
const navbarHeight = ref(0)
const instance = getCurrentInstance()
const state = reactive({
  messageData: [],
})

const { init: initTransparentScroll, opacityScrollHandle } =
  useScrollTransparentNavbar(instance)

// 导航栏初始化完毕
const navbarInitFinishHandle = (info: NavbarRectInfo) => {
  navbarHeight.value = info.height
}

const queryList = (pageNo: any, pageSize: any) => {
  system
    .messages({
      page: pageNo,
      page_size: pageSize,
      type: 'system',
    })
    .then((res) => {
      console.log(res.data, 'getMessageList')
      paging.value.complete(res.data)
    })
    .catch((err: any) => {
      console.log(err, 'getMessageList')
      paging.value.complete(false)
    })
}

onReady(() => {
  initTransparentScroll()
})
onPageScroll((e) => {
  opacityScrollHandle(e.scrollTop)
})
</script>

<template>
  <PageContainer :placeholder-bottom="true">
    <!-- <TnNavbar
      fixed
      :bottom-shadow="false"
      :placeholder="false"
      @init-finish="navbarInitFinishHandle"
    >
      系统消息
    </TnNavbar> -->
    <view class="container">
      <view class="tn-mt-sm">
        <z-paging
          ref="paging"
          v-model="state.messageData"
          :paging-style="{ paddingTop: `${navbarHeight + 10}px` }"
          :safe-area-inset-bottom="true"
          :use-safe-area-placeholder="true"
          @query="queryList"
        >
          <view class="">
            <view
              v-for="(item, index) in state.messageData"
              :key="index"
              class="tn-flex user-lists items-center"
            >
              <view class="tn-pl-sm">
                <view class="tn-flex justify-between tn-text-ellipsis-1">
                  <view class="justify-content-item">
                    <text class="tn-text-lg">{{ item.describe }}</text>
                  </view>
                </view>
                <view class="tn-pt-xs tn-text-ellipsis">
                  <text class="tn-color-gray tn-text-sm">{{ item.content }}</text>
                  <view style="color: #7d7d7d; margin-top: 10rpx">{{ item.msg_time }}</view>
                </view>
              </view>
            </view>
          </view>
        </z-paging>
      </view>

      <view class="tn-tabbar-height" />
    </view>
  </PageContainer>
</template>

<style lang="scss" scoped>
@use './styles/systemlist.scss';
</style>
